package com.example.web.config;


//如果 想要diy一些定制化的功能,只要写这个组件,然后将它交给SpringBoot,SpringBoot就会帮我们自动装配

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Locale;

//扩展SpringMVC
@Configuration
@EnableWebMvc
//  @EnableWebMvc  这个注解就是导入了一个类: DelegatingWebMvcConfiguration : 从容器中获取所有的webmvcconfig;
public class MvcConfig implements WebMvcConfigurer {
    //ViewResolver 实现了视图解析器接口的类, 我们就可以把它看做视图解析器
    @Bean
    public ViewResolver myViewResolve(){
        return new MyViewResolver();
    }

    //自定义了一个自己的视图解析器MyViewResolver
    public static class MyViewResolver implements ViewResolver{
        @Override
        public View resolveViewName(String viewName, Locale locale) throws Exception {
            return null;
        }
    }

    //视图跳转
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
       registry.addViewController("/test1").setViewName("test");
    }
}


